<?php

namespace App\Http\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Category extends Model
{
    //
    function tree(){
        $treeresoult=DB::table('category')
            ->orderBy('cate_order','asc')
            ->get();
        $date=$this->gettree($treeresoult,'cate_name','cate_id','cate_pid' );
        return $date;
    }

    function gettree($date,$file_name,$file_id='id',$file_pid='pid',$pid=0){
        $arr=array();

        foreach ($date as $k=>$v){
            if ($v->$file_pid==$pid){

                             $arr[]=$date[$k];
   
                foreach ($date as $m=>$n){
                    if ($n->$file_pid==$v->$file_id){


                        $arr[]=$date[$m];
                    }
                }
            }
        }

        return $arr;


    }
}
